﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HAVNet.Intros.AST
{
    public class ASTMemberDeclCastOperator : ASTMemberDeclStruct
    {
        public bool             isExplicit  { get; set; }
        public ASTType          type        { get; set; }
        public ASTFormalParam   param       { get; set; }
        public ASTBlock         block       { get; set; }

        public override string ToString ()
        {
            string sAttrs   = ((null == _attrGroups) ? "" : _attrGroups.ToString() + Environment.NewLine);

            //  operatorsMod          = publicMod | unsafeMod | staticMod | externMod,
            //  operatorsMustMod      = publicMod | staticMod,

            string mods     = "";

            if (Mods.has(modifiers, Mods.publicMod)) mods += "public ";
            if (Mods.has(modifiers, Mods.unsafeMod)) mods += "unsafe ";
            if (Mods.has(modifiers, Mods.staticMod)) mods += "static ";
            if (Mods.has(modifiers, Mods.externMod)) mods += "extern ";

            string sExplicitImplicit = isExplicit ? "explicit" : "implicit";
            string sBlock   = (null == block ? ";" : block.ToString());

            return
                sAttrs              +
                mods                +
                sExplicitImplicit   + " " +
                "operator"          + " " +
                type.ToString()     + " " +
                "(" + param.ToString() + ")" + Environment.NewLine +
                sBlock + Environment.NewLine
            ;
        }
    }
}
